package sjms.behavior.china;

/**
 * @ClassName:
 * @Description: 抽象父类
 * @Author fcb
 * @Date 2020/6/5 14:30
 */
public abstract class AbstractLogger {

    public static int INFO = 1;
    public static int DEBUG = 2;
    public static int ERROR = 3;

    protected int level;

    protected AbstractLogger nextLogger;

    public void setNextLogger(AbstractLogger nextLogger){
        this.nextLogger = nextLogger;
    }

    public abstract void write(String message);

    // 公共方法，在这个方法中判断、传递请求
    public void log(int level, String message){
        if(this.level <= level){
            write(message);
        }
        if(nextLogger != null){
            nextLogger.log(level, message);
        }
    }
}
